package com.wyn.common.ineterceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;


@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //定义排除swagger访问的路径配置
        String[] swaggerExcludes=new String[]{"/swagger-ui.html/**","/swagger-resources/**","/webjars/**","/uos-detection.insert.css/**","/csrf/","/v2/**","/uos-detection.insert.js/**"};

        List<String> patterns = new ArrayList<>();
        patterns.add("/User/login");
        patterns.add("/redis/**");
        //mvc配置类中添加拦截器
        registry.addInterceptor(new JWTInterceptor())//需要添加的拦截器类
                .addPathPatterns("/**")//需要拦截的路径
                .excludePathPatterns(patterns)
                .excludePathPatterns(swaggerExcludes);//需要排除的路径
    }
}




